package display.base
{
	import controller.Controller;
	import display.DisplayTextField;
	import events.DisplayEvent;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Henrik Riise Hansen
	 */
	public class DisplayBase extends MovieClip 
	{
		public var control:Controller;
		public var sh:Shell;
		public var ModuleName:String;
		
		public var xPos:int;
		public var yPos:int;
		
		// properties
		
		private var fontType:String;
		private var font:String;
		private var bgSprite:Sprite;
		private var colorOne:uint = 0xcccccc;
		private var colorTwo:uint = 0xffffff;
		private var selectedColorOne:uint = 0x000000;
		private var selectedColorTwo:uint = 0xCCCCCC;
		private var fontColor:uint = 0x000000;
		private var moduleBackGroundColor:uint;
		private var moduleAlpha:Number = 1;
		
		// sprites
		
		public var holder:Sprite;
		
		private var thumbPic:Sprite;
		
		public function DisplayBase() 
		{
			control.addEventListener(DisplayEvent.COLOR_CHANGED, onColorChanged);
			control.addEventListener(DisplayEvent.FONT_CHANGED, onFontChanged);
			control.addEventListener(DisplayEvent.ALPHA_CHANGED, onAlphaChanged);
			control.addEventListener(DisplayEvent.VISIBILITY_CHANGED, onVisibilityChanged);
			
			build();
		}
		
		private function build():void
		{
			holder = new Sprite;
			holder.x  = xPos;
			holder.y  = yPos;
			
			holder.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			holder.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			holder.addEventListener(MouseEvent.MOUSE_OUT, onMouseUp);
			
			addChild(holder);
		}
		
		// screen elements
		
		public function createThumb():void
		{
			var thumbPane:Sprite;
			var stars:Sprite;
			var text:DisplayTextField;
			
			for (var x:int = 0; x < 3; x++)
			{
				thumbPic = new ThumbPicture;
				thumbPic.x = 5;
				thumbPic.y = 5;
				
				text = new DisplayTextField(font,fontColor);
				text.x = 110;
				text.y = 20;
				text.label.text = 'Mats test';
				
				thumbPane = new Sprite;
				thumbPane = createButton(thumbColorOne, thumbColorTwo, 67, 255, 4, 4, 4, 4);
				thumbPane.x = x * 260;
				
				stars = createStars();
				stars.x = 120;
				stars.y = 50;
				
				thumbPane.addChild(thumbPic);
				thumbPane.addChild(text);
				thumbPane.addChild(stars);
				
				thumbHolder.addChild(thumbPane);
			}
			
			mHolder.addChild(thumbHolder);
		}
		
		/*
		
		private function createStars():Sprite
		{
			var sHolder:Sprite = new Sprite;
			var s:Shape;
			
			for (var i:int; i < 5; i++)
			{
				s = new Shape;
				
				s.graphics.beginFill(ratingStarColor, 1);
				s.graphics.lineStyle(1, 0x000000);
				DrawingShapes.drawStar( s.graphics, 0, 0, 5, 3, 6, 16);
				s.graphics.endFill();
				
				s.x = i * 16;
				
				sHolder.addChild(s);
			}
			
			return sHolder;
		}
		
		*/
		
		
		// events
		
		private function onMouseDown(e:MouseEvent):void
		{
			holder.startDrag();
		}
		
		private function onMouseUp(e:MouseEvent):void
		{
			holder.stopDrag();
		}
		
		private function onVisibilityChanged(e:DisplayEvent):void
		{
			if (e.data.item == ModuleName)
			{
				this.visible = e.data.selected;
			}
		}
		
		private function onAlphaChanged(e:DisplayEvent):void
		{
			switch(e.data.itemCategory)
			{
				case 'moduleBackgroundAlpha':
				moduleAlpha = e.data.alpha / 100;
				
				//createModuleBackground();
				break;
			}
		}
		
		private function onColorChanged(e:DisplayEvent):void
		{
			switch(e.data.itemCategory)
			{
				case 'moduleBackgroundColor':
				moduleBackGroundColor = e.data.colorOne;
			
				//createModuleBackground();
				break;
			}
		}
		
		private function onFontChanged(e:DisplayEvent):void
		{
			fontType = e.data.font;
			
			//createButtons();
		}
	}

}